package com.ruoyi.web.controller.buy;

import com.ruoyi.buy.domain.entity.buy0003.Buy0003GetInfoByIdVO;
import com.ruoyi.buy.domain.entity.buy0011.Buy0011TableData;
import com.ruoyi.buy.service.IBuy0009Service;
import com.ruoyi.buy.service.IBuyPurchaseBillService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 角色信息
 * 
 * @author ruoyi
 */
@RestController
@Transactional(rollbackFor = Exception.class)
@RequestMapping("/buy/buy0009")
public class buy0009Controller extends BaseController {
    @Autowired
    private IBuy0009Service buy0009Service;

    @Autowired
    private IBuyPurchaseBillService buyPurchaseBillService;


    /**
     * 查询库存信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Buy0011TableData para)
    {
        startPage();
        List<Buy0011TableData> list = buy0009Service.getList(para);
        return getDataTable(list);
    }

    /**
     * 查询库存信息列表
     */
    @PostMapping("/handleToInv")
    public AjaxResult handleToInv(@RequestBody List<Buy0011TableData> list) throws Exception {
        this.buy0009Service.handleToInv(list);
        return AjaxResult.success("操作成功");
    }

    /**
     * 新增【请填写功能名称】
     */
    @Log(title = "新增请购单转合同", businessType = BusinessType.INSERT)
    @PostMapping("/insertBuyPurchaseBill")
    public AjaxResult insertBuyPurchaseBill(@RequestBody Buy0003GetInfoByIdVO para) throws Exception {
        para.setCreateBy(getUsername());
        return toAjax(buy0009Service.insertBuyPurchaseBill(para));
    }

    @Log(title = "补充请购单转合同", businessType = BusinessType.INSERT)
    @PostMapping("/updateBuyPurchaseBill")
    public AjaxResult updateBuyPurchaseBill(@RequestBody Buy0003GetInfoByIdVO para) throws Exception {
        para.setCreateBy(getUsername());
        return toAjax(buy0009Service.updateBuyPurchaseBill(para));
    }

    /**
     * 新增【请填写功能名称】
     */

    @GetMapping("/getContracts")
    public AjaxResult getContracts() throws Exception {
        return success(buy0009Service.getContracts());
    }

    /**
     * 处理完成提交回采购
     */
    @GetMapping(value = "/{vBillNo}")
    public AjaxResult getContractInfo(@PathVariable("vBillNo") String vBillNo) throws Exception {
        return AjaxResult.success(this.buy0009Service.getPurchaseBillInfo(vBillNo));
    }
}
